#include "../../include/httpLib.hpp"
using namespace std;

// 测试服务器是否能够处理错误请求的情况，如果正文的长度对不上，那就会在下一次处理请求的时候直接返回一个错误响应

int main()
{
    tcpSocket c;
    if (!c.createClient("127.0.0.1", 8080))
    {
        lg(Error, "create client error");
        return 1;
    }
    while (true)
    {
        std::string req = "GET /hello HTTP/1.1\r\nConnection: keep-alive\r\nContent-Length: 50\r\n\r\n";
        while (1)
        {
            assert(c.send(req, false) != -1);
            assert(c.send(req, false) != -1);
            assert(c.send(req, false) != -1);
            assert(c.send(req, false) != -1);
            char buf[1024] = { 0 };
            string ans;
            ssize_t n = c.recv(&ans, 1024, false);
            cout << ans << endl;
            sleep(10);
        }
    }

    return 0;
}